package io.renren.modules.generator.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.generator.entity.IndustryEntity;
import io.renren.modules.generator.service.IndustryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.PrizeEntity;
import io.renren.modules.generator.service.PrizeService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author author
 * @email author@gmail.com
 * @date 2021-07-02 21:57:30
 */
@RestController
@RequestMapping("generator/prize")
public class PrizeController {
    @Autowired
    private PrizeService prizeService;
    @Autowired
    private IndustryService industryService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:prize:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = prizeService.queryPage(params);
        List<IndustryEntity> industries = industryService.queryAll();
        R put = R.ok().put("page", page).put("industries", industries);
        return put;
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:prize:info")
    public R info(@PathVariable("id") Integer id){
		PrizeEntity prize = prizeService.getById(id);

        return R.ok().put("prize", prize);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:prize:save")
    public R save(@RequestBody PrizeEntity prize){
        IndustryEntity industryEntity = industryService.getById(prize.getIndustryId());
        prize.setIndustryName(industryEntity.getIndustryName());
        prizeService.save(prize);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:prize:update")
    public R update(@RequestBody PrizeEntity prize){
        IndustryEntity industryEntity = industryService.getById(prize.getIndustryId());
        prize.setIndustryName(industryEntity.getIndustryName());
		prizeService.updateById(prize);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:prize:delete")
    public R delete(@RequestBody Integer[] ids){
		prizeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
